package com.net.framework.help.progress;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.net.framework.help.dialog.CustomProgressDialog;

/**
 * Author：xiaobin.zhang
 * Email：154722566@qq.com
 * Date：2017-12-08 14:12
 * Desc：<--功能描述-->
 */
public class WebProgressDialogHandler extends Handler {
    public static final int SHOW_PROGRESS_DIALOG = 1;
    public static final int DISMISS_PROGRESS_DIALOG = 2;
    //    private CommonProgressDialog pd;
    private CustomProgressDialog customProgressDialog;
    private Context context;
    private boolean cancelable;

    public WebProgressDialogHandler(Context context, boolean cancelable) {
        super();
        this.context = context;
        this.cancelable = cancelable;
    }

    private void initProgressDialog() {
        if (customProgressDialog == null) {
            customProgressDialog = new CustomProgressDialog(context);
            customProgressDialog.setCancelable(cancelable);
        }
        customProgressDialog.showProgressDialog(context);
    }

    private void dismissProgressDialog() {
//        if (pd != null) {
//            pd.dismiss();
//            pd = null;
//        }
        if (customProgressDialog != null) {
            customProgressDialog.dismissProgressDialog();
            customProgressDialog = null;
        }
    }

    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case SHOW_PROGRESS_DIALOG:
                initProgressDialog();
                break;
            case DISMISS_PROGRESS_DIALOG:
                dismissProgressDialog();
                break;
        }
    }
}